package com.xuanxing123.model;

import com.xuanxing123.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="module",catalog="xuanxing")
@Searchable
@XmlRootElement
public class Module extends BaseObject implements Serializable {
    private Long id;
    private ProductType productType;
    private String name;
    private String target;
    private Integer position;
    private String comments;

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="type_id", nullable=false)
    public ProductType getProductType() {
        return this.productType;
    }
    
    public void setProductType(ProductType productType) {
        this.productType = productType;
    }
    
    @Column(name="name", nullable=false, length=100)
    @SearchableProperty
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Column(name="target", length=100)
    @SearchableProperty
    public String getTarget() {
        return this.target;
    }
    
    public void setTarget(String target) {
        this.target = target;
    }
    
    @Column(name="position", nullable=false)
    @SearchableProperty
    public Integer getPosition() {
        return this.position;
    }
    
    public void setPosition(Integer position) {
        this.position = position;
    }
    
    @Column(name="comments", length=254)
    @SearchableProperty
    public String getComments() {
        return this.comments;
    }
    
    public void setComments(String comments) {
        this.comments = comments;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Module pojo = (Module) o;

        if (productType != null ? !productType.equals(pojo.productType) : pojo.productType != null) return false;
        if (name != null ? !name.equals(pojo.name) : pojo.name != null) return false;
        if (target != null ? !target.equals(pojo.target) : pojo.target != null) return false;
        if (position != null ? !position.equals(pojo.position) : pojo.position != null) return false;
        if (comments != null ? !comments.equals(pojo.comments) : pojo.comments != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (productType != null ? productType.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (target != null ? target.hashCode() : 0);
        result = 31 * result + (position != null ? position.hashCode() : 0);
        result = 31 * result + (comments != null ? comments.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("productType").append("='").append(getProductType()).append("', ");
        sb.append("name").append("='").append(getName()).append("', ");
        sb.append("target").append("='").append(getTarget()).append("', ");
        sb.append("position").append("='").append(getPosition()).append("', ");
        sb.append("comments").append("='").append(getComments()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
